<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<!--只在模块名下面有效 -->
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>集团成员列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div class="searchArea">
				<form id="searchBar">
					<div class="fieldset1 clearFix">
						<div class="fieldBox">
							<div class="label" style="width: 60px;">成员ID</div>
							<div class="field">
								<input name="groupId" id="groupId" type="text" class="ui-textbox" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label" style="width: 80px;">成员名称</div>
							<div class="field">
								<input name="splNm" id="splNm" type="text" class="ui-textbox" value="">
							</div>
						</div>

						<div class="fieldBox">
							<div class="label" style="width: 60px;">关键人</div>
							<div class="field">
								<input name="relInfo" id="relInfo" type="text" class="ui-textbox" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">审核状态</div>
							<div class="field">
								<select name="audStsCd" id="audStsCd" data-value=" ">
									<option value=" " seleted>请选择</option>
									<option value="0" seleted>待提交</option>
									<option value="1" seleted>审核中</option>
									<option value="2" seleted>审核通过</option>
								</select>
							</div>
						</div>

						<div class="clearFix"></div>
						<div class="btnsBox">
							<span id="searchBtn" class="sq-button sq-button-round">查询</span>
							<span onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
							<span onclick="batchCancelGroupMemberRelation();" class="sq-button sq-button-round">解除关联</span>
							<span onclick="addGroupMemberRelation();" class="sq-button sq-button-round">新增集团成员</span>
						</div>
					</div>
				</form>
			</div>
			<div id="ligergridDB" class="sq-grid"></div>
		</div>
	</div>

	<script type="text/javascript">
	var gridDB = null;
	var splTypCd = '${splTypCd}';
	var groupId = '${groupId}';
	$(function () {
		initGridDB();//初始化待办列表
	    $("#searchBar").ligerForm();
	    $("#searchBtn").click(function(event) {
	    	reloadGrid();
	    });
	});
    
    //重新加载GRID
    function reloadGrid(){
    	var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
	        gridDB.setParm(name,data[name]);
	    };
	    gridDB.reload();
    }
    
    //初始化列表
    function initGridDB(){
    	$("#ligergridDB").ligerGrid({
	    	url: '<%=path%>/splGroup/toSplGroupMemberListPage.do?groupId='+groupId,
	    	method : 'get',
            parms:{
                groupId:groupId,
                splTypCd:splTypCd
            },
	        columns: [
	            { display: '成员ID', name: 'id', minWidth: 100 ,align:'left', enabledSort:false},
	            { display: '成员名称', name: 'splName', minWidth: 150 ,align:'left', enabledSort:false},
	            { display: '审核状态', name: 'audStsCdNm', minWidth: 150 ,align:'left', enabledSort:false},
                { display: '成员类型', name: 'splTypCdNm', minWidth: 50 ,align:'left', enabledSort:false},
                { display: '是否为黑名单', name: 'isBlack', minWidth: 50 ,align:'left', enabledSort:false,
                	render:function (rowdata, rowindex, value){
	            		if(rowdata.isBlackList == 1){
	            			return '是';
	            		}else{
	            			return '否'
	            		}
					},
                },
                
//                { display: '成员类型', name: 'splTypCdNm', minWidth: 140 , enabledSort:false},
                { display: '关键人类型', name: 'relTypCdNm', minWidth: 200 ,align:'left', enabledSort:false},
                { display: '关键人', name: 'relInfo', minWidth: 200 ,align:'left', enabledSort:false},
               // { display: '关联地址', name: 'relInfo', minWidth: 200 , enabledSort:false},
                { display: '我司评级', name: 'splLevel', minWidth: 50 ,align:'left', enabledSort:false},
                { display: '操作', name: '', minWidth: 140 ,align:'left', enabledSort:false,
	            	render:function (rowdata, rowindex, value){
	            		var h="";
                        h+='<a class="sq-button-hasicon" href="javascript:cancelGroupMemberRelation(';
                        h+="'"+rowdata.id+"','"+rowdata.splNm+"'";
                        h+=")\"><i class='sqBtnIco_4'></i>解除关联</a>";
						return h;
					}},
	        ],
	        pageSize:10,
	        pageSizeOptions: [10, 20, 30, 40, 50, 100],//按照自己的喜好选择不同的页面显示条数
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-30,
	        checkbox:true,
	        rownumbers:true
	    });
	    gridDB = liger.get("ligergridDB");
	    gridDB.setHeight(100);
	    //gridDB.options.isSingleCheck=true;
    }

    var callback = function () {
		gridDB.reload();
    };
  //解除关联
  function cancelGroupMemberRelation(id,splNm){
      var _id = id;//成员id
      if (StringUtils.isEmpty(_id)) {
          $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
          return;
      }
      $.ligerDialog.confirm("解除关联后，该成员将不会在集团成员中显示，确定解除吗？", function (flag) {
          if (flag == false)return;
          var wait_dialog;
          $.ajax({
              type: 'post',
              dataType: 'json',
              data: {id: _id,groupId:groupId},
              url: '<%=path%>/splGroup/toCancelGroupMemberRelation.do',
              beforeSend: function () {
                  wait_dialog = $.ligerDialog.SQalert({
                      content: LogUtils.LOG_CMM_DATA_LOADING,
                      SQ_type: "waitting"
                  });
              },
              success: function (msg) {
                  wait_dialog.close();
                  if (msg.success == 1) {
                      $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                      gridDB.reload();
                  } else {
                      $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                  }
              }
          });
      });
  }
  
  function addGroupMemberRelation(){
	  console.log("groupId"+groupId)
	  $.ligerDialog.SQopen({
          width: 900,
          height:500,
          title : '新增集团成员',
          url:'<%=path%>/splGroup/toAddSplGroupMember.do?groupId='+groupId,
          data:{groupId:groupId}
         /*  buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ] */
      });
  }


    //批量解除关联
    function batchCancelGroupMemberRelation(){
        var selectedRows = gridDB.getSelectedRows();
        if (selectedRows.length == 0) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
            return;
        }
        var _ids = [];
        for(var i= 0; i< selectedRows.length; i++){
            _ids.push(selectedRows[i].id);
        }
        console.log("批量解除成员关系,ids=="+JSON.stringify(ids));
        $.ligerDialog.confirm("解除关联后，该成员将不会在集团成员中显示，确定解除吗？", function (flag) {
            if (flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids),groupId:groupId},
                url: '<%=path%>/splGroup/toCancelGroupMemberRelation.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING,
                        SQ_type: "waitting"
                    });
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        gridDB.reload();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }



    //格式化时间
    function renderDate2(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

	function clearBtn(){
		$("#resetBtn").click();  //重置 input-text
		var form = liger.get("searchBar");
        form.setData({  //重置select等特殊表单
            //"orgCd": " ",
            "groupId":"",
            "splNm":"",
			"relInfo":""
        });
       //searchOrgTree.clear();
	}
</script>

</body>
</html>
